var defaultPageSize = 20;
function getItemHtml(totalCount,pageSize,currPage,id,callback){
	return '<a href="#" onclick="javascript:page('+totalCount+','+pageSize+','+currPage+',\''+id+'\',\''+callback+'\')">'+currPage+'</a>';
}
function page(totalCount,pageSize,currPage,id,callback,isfirst){
	var in_totalCount = parseInt(totalCount);
	var in_pageSize = parseInt(pageSize);
	var in_currPage = parseInt(currPage);
	
	var start = (currPage-1)*pageSize;
	
	if(!isfirst)
		eval(callback+'('+start+','+pageSize+')');
	
	var zz = 5;
	var pagehtml = '';
	var pageCount = Math.ceil(in_totalCount/in_pageSize) ;
	if (pageCount<=1){
		jQuery("#"+id).html(pagehtml);
		return;
	}
	var in_prevPage = in_currPage<=1?1:(in_currPage-1);
	var in_nextPage = in_currPage>=pageCount?pageCount:(in_currPage+1);
	
	
	
	var prevPageHtml = '<a href="#"  onclick="javascript:page('+in_totalCount+','+in_pageSize+','+in_prevPage+',\''+id+'\',\''+callback+'\')">◀上一页</a>';
	var nextPageHtml = '<a href="#"  onclick="javascript:page('+in_totalCount+','+in_pageSize+','+in_nextPage+',\''+id+'\',\''+callback+'\')">下一页▶</a>';

	if(pageCount >= 0 && pageCount<=10 ){
		pagehtml = '';
		for(var i= 1;i<=pageCount;i++){
			pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback);
		}
		pagehtml +=(prevPageHtml+nextPageHtml);
	}else if(pageCount> 10){
		if(in_currPage <= (1+zz+1)){
			pagehtml = '';
			for(var i= 1;i<=10;i++){
				pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback);
			}
			pagehtml +=('•••'+prevPageHtml+nextPageHtml);
		}else if(in_currPage >= pageCount-zz-1){
			pagehtml = 
				getItemHtml(in_totalCount,in_pageSize,1,id,callback)+
				'•••';
			for(var i = pageCount-8;i<=pageCount;i++){
				pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback);
			}
			pagehtml +=(prevPageHtml+nextPageHtml);
		}else{
			pagehtml = 
				getItemHtml(in_totalCount,in_pageSize,1,id,callback)+
				'•••';
			for(var i = in_currPage-zz;i<=in_currPage+zz;i++){
				pagehtml += getItemHtml(in_totalCount,in_pageSize,i,id,callback);//'<a href="#" onclick="javascript:page('+in_totalCount+','+pageSize+','+i+',\''+id+'\')">'+i+'</a>';
			}
			pagehtml +='•••<a href="#" >'+pageCount+'</a>'+prevPageHtml+nextPageHtml;
		}
		
		
	}
	jQuery("#"+id).html(pagehtml);
	jQuery("#"+id+" a").removeClass('on') ;
	jQuery("#"+id+" a:eq("+(in_currPage-1)+")").addClass('on') ;
	
}